﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
    <h2>
       Add Or Update Contacts!
    </h2>
    <p>
        <asp:Button ID="cmdAdd" runat="server" onclick="cmdAdd_Click" Text="Add" />
    </p>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
    DataKeyNames="ID" DataSourceID="SqlDataSource1" 
    onselectedindexchanged="GridView1_SelectedIndexChanged" AllowPaging="True" 
        AllowSorting="True" onrowupdating="GridView1_RowUpdating" 
        BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" 
        CellPadding="3" GridLines="Vertical" Height="162px" Width="830px">
        <AlternatingRowStyle BackColor="#DCDCDC" />
        <Columns>
            <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" 
                ReadOnly="True" SortExpression="ID" />
            <asp:BoundField DataField="Firstname" HeaderText="Firstname" 
                SortExpression="Firstname" />
            <asp:BoundField DataField="Lastname" HeaderText="Lastname" 
                SortExpression="Lastname" />          
            <asp:BoundField DataField="Intial" HeaderText="Intial" 
                SortExpression="Intial" />
            <asp:BoundField DataField="ChangedBy" HeaderText="ChangedBy" 
                SortExpression="ChangedBy" />
            <asp:CommandField ShowEditButton="True" />
            <asp:CommandField SelectText="Audit Trail" ShowSelectButton="True" /> 
             
        </Columns>
        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
        <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
        <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
        <SortedAscendingCellStyle BackColor="#F1F1F1" />
        <SortedAscendingHeaderStyle BackColor="#0000A9" />
        <SortedDescendingCellStyle BackColor="#CAC9C9" />
        <SortedDescendingHeaderStyle BackColor="#000065" />

</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
    DeleteCommand="DELETE FROM [Contact] WHERE [ID] = @ID" 
    InsertCommand="INSERT INTO [Contact] ([Firstname], [Lastname],[Intial], [ChangedBy]) VALUES (@Firstname, @Lastname,  @Intial, @ChangedBy)" 
    SelectCommand="SELECT * FROM [Contact] order by id desc" 
    
    UpdateCommand="UPDATE [Contact] SET [Firstname] = @Firstname, [Lastname] = @Lastname,[Intial] = @Intial, [ChangedBy] = @ChangedBy WHERE [ID] = @ID" 
    oninserting="SqlDataSource1_Inserting" onupdating="SqlDataSource1_Updating" 
        oninserted="SqlDataSource1_Inserted">
    <DeleteParameters>
        <asp:Parameter Name="ID" Type="Int32" />
    </DeleteParameters>
    <InsertParameters>
        <asp:Parameter Name="Firstname" Type="String" />
        <asp:Parameter Name="Lastname" Type="String" />        
        <asp:Parameter Name="Intial" Type="String" />
        <asp:Parameter Name="ChangedBy" Type="String" />
    </InsertParameters>
    <UpdateParameters>
        <asp:Parameter Name="Firstname" Type="String" />
        <asp:Parameter Name="Lastname" Type="String" />     
        <asp:Parameter Name="Intial" Type="String" />
        <asp:Parameter Name="ChangedBy" Type="String" />
        <asp:Parameter Name="ID" Type="Int32" />
    </UpdateParameters>
</asp:SqlDataSource>

</asp:Content>

